package top.frsf.envi;

import top.frsf.GamePanel;

import java.awt.*;
import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;

/**
 * @BelongsProject: MiniPZ
 * @BelongsPackage: top.frsf.envi
 * @Author: FRSF
 * @CreateTime: 2022-09-06  17:05
 * @Description: 环境元素启动器
 * @Version: 1.0
 */
public class EnvStart {


    public static final String PREFIX = "src/main/resources/envi/";

    // 背景图片
    public final Background background = new Background(PREFIX + "background.jpg",
            0, 35, 1400, 600);
    // 阳光商店
    public final ShopBox shopBox = new ShopBox(PREFIX + "ShopBox.png",
            200, 35, 446, 87);
    // 铲子框
    public final ShovelBox shovelBox = new ShovelBox(PREFIX + "ShovelBox.png",
            645, 35, 70, 72);
    // 铲子
    public final Shovel shovel = new Shovel(PREFIX + "Shovel.png",
            645, 35, 70, 72);
    // 主页
    public final Home home = new Home();

    // 阳光List
    public final ArrayList<Sun> sunList = new ArrayList<>();

    public final ArrayList<Sun> removeSunList = new ArrayList<>();

    public Integer sunSum = 500;

    // 草地初始化
    public static final ArrayList<Grand> grandList = new ArrayList<>();

    static {
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 9; j++) {
                grandList.add(new Grand("", 80 + j * 80, 120 + i * 95));
            }
        }
    }

    public void paintEnvi(Graphics g) {
        background.paintSelf(g);

        // 开局动画结束后
        if (background.rightMove && background.leftMove) {
            shopBox.paintSelf(g);
            shovelBox.paintSelf(g);
            shovel.paintSelf(g);


            // 移除已收集的阳光
            sunList.removeAll(removeSunList);
            if (GamePanel.fps % 100 == 1)
                removeSunList.clear();
            // 遍历显示阳光
            for (Sun sun1 : sunList) {
                sun1.paintSelf(g);
            }
            // 绘制收集的阳光值
            g.drawString(String.valueOf(sunSum), 230, 110);


            // 草地辅助线便利
            for (Grand grand : grandList) {
                grand.paintSelf(g);
            }
        }
    }


    public void SunTimerTask() {
        Timer timer = new Timer();
        TimerTask task = new TimerTask() {
            @Override
            public void run() {
                sunList.add(Sun.getSunObj());
            }
        };
        timer.schedule(task, 10000, 10000);
    }
}
